package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjWorkSpareMaterialAnnex;
import com.zb.mapper.ZjWorkSpareMaterialAnnexMapper;
import com.zb.service.ZjWorkSpareMaterialAnnexService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 工单备件物料附件表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-10-26
 */
@Service
public class ZjWorkSpareMaterialAnnexServiceImpl extends ServiceImpl<ZjWorkSpareMaterialAnnexMapper, ZjWorkSpareMaterialAnnex> implements ZjWorkSpareMaterialAnnexService {

    // 根据工单备件物料表ID删除附件
    @Override
    public void deleteByWorkSpareMaterialIds(List<Long> workSpareMaterialIds) {
        if (CollectionUtil.isEmpty(workSpareMaterialIds)) {
            return;
        }
        QueryWrapper<ZjWorkSpareMaterialAnnex> wrapper = new QueryWrapper<>();
        wrapper.in("work_spare_material_id", workSpareMaterialIds);
        this.remove(wrapper);
    }

    // 根据工单备件物料ID获取物料附件信息
    @Override
    public List<ZjWorkSpareMaterialAnnex> getByWorkSpareMaterialIds(List<Long> workSpareMaterialIds) {
        if (CollectionUtil.isEmpty(workSpareMaterialIds)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjWorkSpareMaterialAnnex> wrapper = new QueryWrapper<>();
        wrapper.select("id", "work_spare_material_id", "image");
        wrapper.in("work_spare_material_id", workSpareMaterialIds);
        return this.list(wrapper);
    }
}
